package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import Models.BarrelConditioning;

public class BarrelConditioningPresenter extends AbstractPresenter<BarrelConditioning> {
	final String SINGLEITEM = "barrelConditioning";
	final String MULTIITEM = "barrelConditionings";
	
	public ArrayList<BarrelConditioning> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public BarrelConditioning tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public BarrelConditioning createItemFromJSONObject(JSONObject jsonObject){
		BarrelConditioning item = new BarrelConditioning();
		try{
			item.setBarrelBatch(jsonObject.getString("BCBatches"));
			item.setBarrelConditioningID(jsonObject.getInt("BCId"));
			item.setBarrelDatePkg(getDateFromString(jsonObject.getString("BCDatePkg")));
			item.setBarrelOrigVol(jsonObject.getDouble("BCOrigVol"));
			item.setBarrelVesselID(jsonObject.getInt("BCVesselID"));
			item.setBarrelVolLeft(jsonObject.getDouble("BCVolLeft"));
			item.setFillDate(getDateFromString(jsonObject.getString("BCFillDate")));
			item.setPkgyet(jsonObject.getBoolean("BCPackaged"));
			
			return item;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(BarrelConditioning item){
		try{
			JSONObject json = new JSONObject();
			json.put("BCBatches", item.getBarrelBatch());
			json.put("BCId", item.getBarrelConditioningID());
			json.put("BCDatePkg", getDate(item.getBarrelDatePkg()));
			json.put("BCOrigVol", item.getBarrelOrigVol());
			json.put("BCVesselID", item.getBarrelVesselID());
			json.put("BCVolLeft", item.getBarrelVolLeft());
			json.put("BCFillDate", getDate(item.getFillDate()));
			json.put("BCPackaged", item.isPkgyet());
			
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public BarrelConditioning getEmptyEntity(){
		BarrelConditioning entity = new BarrelConditioning();
		return entity;
	}
}
